package cn.edu.ujn.lab3.c;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.edu.ujn.lab3.dao.User;
import cn.edu.ujn.lab3.service.IUserService;

@Controller
public class UserController {
	@Autowired
	private IUserService userService;
	
	@RequestMapping("/login.action")
	public String login(String usercode,String password,Model model,HttpSession session) {
		User findUser = this.userService.findUser(usercode, password);
		if(findUser!=null) {
			session.setAttribute("USER_SESSION", findUser);
			return "customer";
		} 
		model.addAttribute("msg","用户名或密码错误，请重新登录！");
		return "login";
	}
	
	
	@RequestMapping("/toLogin")
	public String toLogin() {
		return "login";
	}

}
